# -*- coding: utf-8 -*-
import sqlite3
import csv

def criar_bd():
    conn = sqlite3.connect("mocoto.bd")
    c = conn.cursor()
    c.execute('''create table if not exists professores (id interger, name text,
                grau text, curso text, categoria text, regime text,
                ano text,tipo text, establecimento text)''')
    conn.commit()
    conn.close()
pass

def incerir_bd():
    conn = sqlite3.connect("mocoto.bd")
    c = conn.cursor()
 
    for k in range(0,10):
        f = open("rebcsv\\reb{0}.csv".format(str(k)), 'rb')
        reader = csv.reader(f)
        for row in reader:
            c.execute('''insert into professores (id, name, grau, curso, categoria, regime, ano, tipo, establecimento)
                        values ("{0}", "{1}", "{2}", "{3}", "{4}", "{5}", "{6}", "{7}", "{8}")'''
                        .format(str(row[0]).replace('"', '\''), str(row[1]).replace('"', '\''),
                                str(row[2]).replace('"', '\''), str(row[3]).replace('"', '\''),
                                str(row[4]).replace('"', '\''), str(row[5]).replace('"', '\''),
                                str(row[6]).replace('"', '\''), str(row[7]).replace('"', '\''),
                                str(row[8]).replace('"', '\'')))
 
            pass
    conn.commit()
    conn.close()
pass
    
  
 
criar_bd()
incerir_bd()
